package com.bjtech.web.action.management;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bjtech.dao.BaseCityInfoDao;
import com.bjtech.dao.BaseCommunityInfoDao;
import com.bjtech.dao.BaseProjectInfoDao;
import com.bjtech.dao.BaseShareAreaInfoDao;
import com.bjtech.dao.BaseStationInfoDao;
import com.bjtech.domain.BaseCityInfo;
import com.bjtech.domain.BaseCommunityInfo;
import com.bjtech.domain.BaseProjectInfo;
import com.bjtech.domain.BaseStationInfo;
import com.bjtech.domain.query.BaseCityInfoQuerySpec;
import com.bjtech.domain.query.BaseProjectInfoQuerySpec;
import com.bjtech.web.action.LyheatBaseAction;

public class BaseProjectInfoAction extends LyheatBaseAction {

	private static final long serialVersionUID = 1L;
	private BaseProjectInfoDao baseProjectInfoDao;
	private BaseCommunityInfoDao baseCommunityInfoDao;
	private BaseStationInfoDao baseStationInfoDao;
	private BaseProjectInfoQuerySpec selectBean;
	
	private List comList;//小区列表
	private List stationList;//换热站列表
	
	private List shareAreaList;
	private BaseShareAreaInfoDao baseShareAreaInfoDao;
	
	private BaseCityInfoDao baseCityInfoDao;
	private List baseCityInfoList;
	private Map tjParam = new HashMap();
	
	private String custom;
	
	public void prepare() throws Exception {

	}
	
	public BaseProjectInfoAction() throws Exception{
		model = new BaseProjectInfo();
		selectBean = new BaseProjectInfoQuerySpec();
	}
	
	public void setBaseProjectInfoDao(BaseProjectInfoDao baseProjectInfoDao) {
		this.baseProjectInfoDao = baseProjectInfoDao;
	}

	public String execute(){
		return this.list();
	}
	
	public String list(){
		Integer role = getUser().getUserRole();
		Long projectId = getUser().getProjectId();
		if(role.intValue()!=1){
			if(projectId!=null){
				selectBean.setUser_role(role);
				selectBean.setProject_id(projectId);
			}
		}
		selectBean.queryParamString();
		list = this.baseProjectInfoDao.selectEntityPaginatedList(new BaseProjectInfo(),selectBean);
		this.baseCityInfoList = this.baseCityInfoDao.selectEntityPaginatedList(new BaseCityInfo(), new BaseCityInfoQuerySpec());
		return "list";
	}
	
	public String add(){
		comList = baseCommunityInfoDao.selectEntityList(new BaseCommunityInfo(), new BaseProjectInfoQuerySpec());
		stationList = baseStationInfoDao.selectEntityList(new BaseStationInfo(), new BaseCityInfoQuerySpec());
		return "edit";
	}
	
	public String save(){
		BaseProjectInfo entity = (BaseProjectInfo)model;
		if(entity.getId()==null){
			baseProjectInfoDao.insertEntity(entity);
		}else{
			baseProjectInfoDao.updateEntity(entity);
		}
		return "success";
	}
	
	public String edit(){
		comList = baseCommunityInfoDao.selectEntityList(new BaseCommunityInfo(), new BaseProjectInfoQuerySpec());
		stationList = baseStationInfoDao.selectEntityList(new BaseStationInfo(), new BaseCityInfoQuerySpec());
		model = this.baseProjectInfoDao.selectEntity(new BaseProjectInfo(),id);
		return "edit";
	}

	public String view(){
		model = this.baseProjectInfoDao.selectEntity(new BaseProjectInfo(),id);
		shareAreaList =  baseShareAreaInfoDao.selectShareAreaListByProjId(id);
		tjParam = this.baseProjectInfoDao.selectTjParam(id);
		return "view";
	}
	
	public String viewXq(){
		model = this.baseProjectInfoDao.selectEntity(new BaseProjectInfo(),id);
		shareAreaList =  baseShareAreaInfoDao.selectShareAreaListByProjId(id);
		tjParam = this.baseProjectInfoDao.selectTjParam(id);
		custom="BaseProjectInfo/viewXq.jsp";
		return "custom";
	}
	
	public String delete(){
		this.baseProjectInfoDao.deleteProjectLinkedObjs(id);
		model = this.baseProjectInfoDao.deleteEntity(new BaseProjectInfo(),id);
		return "success";
	}
	
	public BaseProjectInfoQuerySpec getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(BaseProjectInfoQuerySpec selectBean) {
		this.selectBean = selectBean;
	}

	public BaseCommunityInfoDao getBaseCommunityInfoDao() {
		return baseCommunityInfoDao;
	}

	public void setBaseCommunityInfoDao(BaseCommunityInfoDao baseCommunityInfoDao) {
		this.baseCommunityInfoDao = baseCommunityInfoDao;
	}

	public BaseStationInfoDao getBaseStationInfoDao() {
		return baseStationInfoDao;
	}

	public void setBaseStationInfoDao(BaseStationInfoDao baseStationInfoDao) {
		this.baseStationInfoDao = baseStationInfoDao;
	}

	public BaseProjectInfoDao getBaseProjectInfoDao() {
		return baseProjectInfoDao;
	}

	public List getComList() {
		return comList;
	}

	public void setComList(List comList) {
		this.comList = comList;
	}

	public List getStationList() {
		return stationList;
	}

	public void setStationList(List stationList) {
		this.stationList = stationList;
	}

	public List getShareAreaList() {
		return shareAreaList;
	}

	public void setShareAreaList(List shareAreaList) {
		this.shareAreaList = shareAreaList;
	}

	public BaseShareAreaInfoDao getBaseShareAreaInfoDao() {
		return baseShareAreaInfoDao;
	}

	public void setBaseShareAreaInfoDao(BaseShareAreaInfoDao baseShareAreaInfoDao) {
		this.baseShareAreaInfoDao = baseShareAreaInfoDao;
	}

	public BaseCityInfoDao getBaseCityInfoDao() {
		return baseCityInfoDao;
	}

	public void setBaseCityInfoDao(BaseCityInfoDao baseCityInfoDao) {
		this.baseCityInfoDao = baseCityInfoDao;
	}

	public Map getTjParam() {
		return tjParam;
	}

	public void setTjParam(Map tjParam) {
		this.tjParam = tjParam;
	}

	public List getBaseCityInfoList() {
		return baseCityInfoList;
	}

	public void setBaseCityInfoList(List baseCityInfoList) {
		this.baseCityInfoList = baseCityInfoList;
	}

	public String getCustom() {
		return custom;
	}

	public void setCustom(String custom) {
		this.custom = custom;
	}
}
